<?php
/**
 * Created by: i@fedax.cn
 * Date: 2018/7/16 22:40
 * 帅帅吴
 */

namespace app\admin\controller;

use app\admin\model\SystemTheme as SystemThemeModel;
use app\admin\model\ExclusiveTheme as ExclusiveThemeModel;
use app\admin\model\ExclusiveGive as ExclusiveGiveModel;
class Theme extends Index
{
    /**
     * @return \think\response\View
     * 专属主题渲染模板
     *帅帅吴
     */
    public function exclusiveIndex()
    {
        return view();
    }

    /**
     * @return \think\response\Json
     * 专属主题数据
     * 帅帅吴
     */
    public function exclusiveIndexData()
    {
        $exclusiveThemeModel = new ExclusiveThemeModel();
        $data = $exclusiveThemeModel->getDataList();
        return json($data);
    }
    public function exclusiveAdd()
    {
      //  halt($_FILES);
        $exclusiveThemeModel = new ExclusiveThemeModel();
        $res = $exclusiveThemeModel->exclusiveAdd();
        if($res)  $this->success(lang('add').lang('success'));
        else  $this->error(lang('add').lang('false'));
    }

    public function themeExclusiveUserAdd()
    {
        $id = input('get.id');
        return view()->assign('id',$id);
    }

    public function themeExclusiveUserAddData()
    {
        $exclusiveThemeModel = new ExclusiveThemeModel();
        $res = $exclusiveThemeModel->themeExclusiveUserAddData();
        return $res;
    }

    /**
     * @return $this
     * @user 帅吴
     * @date 2019/1/3
     * @time 18:38
     * @title 专属主题使用者
     */
    public function ThemeExclusiveDetail()
    {
        $exclusiveGiveModel = new ExclusiveGiveModel();
        $data = $exclusiveGiveModel->themeExclusiveDetail();
        //  halt($data);
        return view()->assign('data',$data);

    }


    /**
     * @return \think\response\View
     * 渲染系统主题模板
     */
    public function systemIndex()
    {
        return view();
    }

    /**
     * @return \think\response\Json
     * 渲染系统模板数据
     */
    public function systemIndexData()
    {
        $systemThemeModel = new SystemThemeModel();
        $data = $systemThemeModel->getDataList();
        return json($data);
    }

    /**
     * @return \think\response\Redirect
     * 添加系统主题
     */
    public function systemAdd()
    {
        $systemThemeModel = new SystemThemeModel();
        $res = $systemThemeModel->systemAdd();
        if($res)  $this->success(lang('add').lang('success'));
        else  $this->error(lang('add').lang('false'));

    }
    /**
     * @return \think\response\Redirect
     * 上架下架系统主题
     */
    public function systemChangeStatus()
    {
        $systemThemeModel = new SystemThemeModel();
        $systemDetail = $systemThemeModel ->where('system_theme_id',input('id'))->find();
        $newData['status'] = $systemDetail['status'] === 1?0:1;
        $res = $systemThemeModel->save($newData,['system_theme_id' =>input('id')]);

        if($res) return ['code'=>100,'msg'=>'修改成功'];
        else return ['code'=>-100,'msg'=>'修改失败'];

    }
}